home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / COPYEX.CPP < prev    next >
Text File  |  1997-05-06  |  929b  |  45 lines

  1.  #include <algorithm>
  2.  #include <vector>    
  3.  
  4.  using namespace std;
  5.  
  6.  int main ()
  7.  {
  8.    int d1[4] = {1,2,3,4};
  9.    int d2[4] = {5,6,7,8};
  10.    //
  11.    // Set up three vectors.
  12.    //
  13.    vector<int> v1(d1+0, d1+4), v2(d2+0, d2+4), v3(d2+0, d2+4);
  14.    //
  15.    // Set up one empty vector.
  16.    //
  17.    vector<int> v4;
  18.    //
  19.    // Copy v1 to v2.
  20.    //
  21.    copy(v1.begin(), v1.end(), v2.begin());
  22.    //
  23.    // Copy backwards v1 to v3.
  24.    //
  25.    copy_backward(v1.begin(), v1.end(), v3.end());
  26.    //
  27.    // Use insert iterator to copy into empty vector.
  28.    //
  29.    copy(v1.begin(), v1.end(), back_inserter(v4));
  30.    //
  31.    // Copy all four to cout.
  32.    //
  33.    ostream_iterator<int> out(cout," ");
  34.    copy(v1.begin(),v1.end(),out);
  35.    cout << endl;
  36.    copy(v2.begin(),v2.end(),out);
  37.    cout << endl;
  38.    copy(v3.begin(),v3.end(),out);
  39.    cout << endl;
  40.    copy(v4.begin(),v4.end(),out);
  41.    cout << endl;
  42.  
  43.    return 0;
  44.  }
  45.